import HomePage_TableComponent from "../../../../component/table";
import dayjs from 'dayjs';
import { useEffect, useRef, useState } from "react";
import { $Http } from "../../../../../../network";
import { message } from "antd";
import { $eventBus, $EventBus_off, $EventBus_on, $export_excel } from "../../../../../../common/utils";
// 主页-统计查询页面-线路数值分析页面
const HomePage_StatisticalQueryPage_LineNumericalAnalysisPage: React.FC = () => {
    const initParamsData = useRef<object>({})
    const paramsData = useRef<object>({})
    let [pageNo, setPageNo] = useState<number>(1)
    let [pageSize, setPageSize] = useState<number>(10)
    const [sourceData, setSourceData] = useState<object>({})
    const [isModal, setIsModal] = useState<boolean>(false)
    const [isDeleteModal, setIsDeleteModal] = useState<boolean>(false)
    const [modalData, setModalData] = useState<object>({})
    const [isConfirm, setIsConfirm] = useState<boolean>(false)
    const columnList = [
        {
            title: '序号',
            width: 60,
            render: (text: string, record: object, idx: number) => idx + 1,
        },
        {
            title: '线路',
            minWidth: 60,
            dataIndex: 'age',
            render: (text: string) => text ?? "-"
        },
        {
            title: '类型',
            minWidth: 60,
            dataIndex: 'age',
            render: (text: string) => text ?? "-"
        },
        {
            title: '回流线电流(A)',
            minWidth: 110,
            dataIndex: 'address',
            align: "right",
            render: (text: string) => text ?? "-"
        },
        {
            title: '架空地线电流(A)',
            children: [
                {
                    title: 'A相',
                    minWidth: 50,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
                {
                    title: 'B相',
                    minWidth: 50,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
                {
                    title: 'C相',
                    minWidth: 50,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
                {
                    title: '总和',
                    minWidth: 60,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
            ]
        },
        {
            title: '',
        },
        {
            title: '金属护套电流(A)',
            children: [
                {
                    title: 'A相',
                    minWidth: 50,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
                {
                    title: 'B相',
                    minWidth: 50,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
                {
                    title: 'C相',
                    minWidth: 50,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
                {
                    title: '总和',
                    minWidth: 60,
                    dataIndex: 'age',
                    align: "right",
                    render: (text: string) => text ?? "-"
                },
            ]
        },
        {
            title: '更新时间',
            minWidth: 85,
            dataIndex: 'age',
            render: (text: string) => text ?? "-"
        },
    ];
    const http_search = () => {
        $Http("search", { typeName: "统计查询/线路数值分析", ...paramsData.current, pageNo, pageSize }).then((res) => {
            setSourceData({ ...res["data"] })
        })
    }

    const change_pagination = (no: number, size: number) => {
        pageNo = no
        pageSize = size
        setPageNo(pageNo)
        setPageSize(pageSize)
        http_search()
    }

    const change_export = (list: Array<number>) => {
        $export_excel("统计查询/线路数值分析", list)
    }


    // 广播函数数据
    const eventBusFuncData = {
        // 头部操作新增
        headerOperationAdd: (data: object) => {
            setModalData({ type: "add" })
            setIsModal(true)
        },
        // 头部操作初始参数
        headerOperationInitParamsData: (data: object) => {


            initParamsData.current = data["data"]["initParamsData"]
            paramsData.current = data["data"]["initParamsData"]
            http_search()
        },
        // 头部操作查询
        headerOperationSearch: (data: object) => {
            pageNo = 1
            setPageNo(pageNo)
            paramsData.current = { ...paramsData.current, ...data["data"]["paramsData"] }
            http_search()
        },
        // 头部操作条件的开关
        headerOperationConditionSwitch: (data: object) => {
            pageNo = 1
            setPageNo(pageNo)
            paramsData.current = { ...initParamsData.current }
            http_search()
        },
        // 确认操作
        confirmOperation: (data: object) => {
            $Http("delete", { typeName: "统计查询/线路数值分析", id: data["data"]["id"], dispatchNumber: data["data"]["dispatchNumber"] }).then((res) => {
                message.success(res["success"])
                setTimeout(() => {
                    $eventBus.emit("headerOperationConditionSwitch", { source: "HomePage_DataMaintenancePage_SubstationMaintenancePage", explain: "删除成功，请关闭头部操作条件，并查询", data: { isOpen: false } })
                })
                setIsDeleteModal(false)
            })
        }
    }



    useEffect(() => {
        $EventBus_on(eventBusFuncData)
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])
    return (

        <HomePage_TableComponent name="homePageStatisticalQueryPageLineNumericalAnalysisPageTable"
            smallPaddingList={["架空地线电流(A)", "金属护套电流(A)", "A相", "B相", "C相", "总和"]}
            smallFontList={["A相", "B相", "C相", "总和"]}
            borderLeftList={["", "更新时间"]}
            borderRightList={["回流线电流(A)", ""]}
            alignRightList={["回流线电流(A)", "A相", "B相", "C相", "总和"]}
            columnList={columnList} pageNo={pageNo} pageSize={pageSize} sourceData={sourceData} change_pagination={change_pagination} change_selectedRowList={change_export} />

    )
}

export default HomePage_StatisticalQueryPage_LineNumericalAnalysisPage